//
//  BKFilterTableViewCell.m
//  bestkeep
//
//  Created by 李明 on 2016/12/13.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKFilterTableViewCell.h"
#import "BKMyCommon.h"
#import "BKPhoneNumberSave.h"

@interface BKFilterTableViewCell ()

@property (nonatomic, copy) NSString *registerPhone;

@end

@implementation BKFilterTableViewCell



- (UILabel *)phoneInfo {
    
    if (!_phoneInfo) {
        _phoneInfo = [[UILabel alloc] init];
       // _registerPhone = [Userinfo getCellPhone];
        [self addSubview:_phoneInfo];
    }
    return _phoneInfo;
}
- (UILabel *)phoneNumber {
    
    if (!_phoneNumber) {
        _phoneNumber = [[UILabel alloc] init];
        [self addSubview:_phoneNumber];
    }
    return _phoneNumber;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.phoneNumber.font = UIFontLarge;
        self.phoneNumber.textColor = RGBCOLOR(64, 64, 64, 1);
        [self.phoneNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.left.mas_equalTo(16);
            make.height.mas_equalTo(18);
        }];
        [self.phoneInfo setTextAlignment:NSTextAlignmentRight];
        self.phoneInfo.font = UIFontSmall;
        self.phoneInfo.textColor = RGBCOLOR(136, 136, 136, 1);
        [self.phoneInfo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.right.mas_equalTo(self.mas_right).offset(-16);
        }];
        
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.backgroundColor = RGBCOLOR(218, 218, 218, 1);
        [self addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.mas_top);
            make.left.mas_equalTo(self.mas_left);
            make.right.mas_equalTo(self.mas_right);
            make.height.mas_equalTo(0.5f);
        }];
        
    }
    return self;
}

- (void)getFilterInfoFromArray:(AddressBookPerson *)addressBookPerson {
    
    self.phoneNumber.text = [self formattingPhoneNumber:addressBookPerson.phoneNumber];
    if ([addressBookPerson.phoneNumber isEqualToString:_registerPhone]) {
        self.phoneInfo.text = [NSString stringWithFormat:@"%@",@"账户绑定号码"];
    }else {
        self.phoneInfo.text = addressBookPerson.name;
    }
    
}
- (void)getFilterInfoFromDictionary:(BKPhoneContactInfo *)contactInfo {
    
    NSString *phoneNumber = contactInfo.phoneNumber;
    NSString *phoneInfo = contactInfo.phoneName;
    self.phoneNumber.text = [self formattingPhoneNumber:phoneNumber];
    self.phoneInfo.text = phoneInfo;
}

//标准化 电话号码 111 1111 1111
- (NSString *)formattingPhoneNumber:(NSString *)number{
    
    NSMutableString *mutStr = [number mutableCopy];
    if (mutStr.length) {
        
        if (number.length > 3 && ![[number substringWithRange:NSMakeRange(3, 1)] isEqualToString:@" "]) {
            [mutStr insertString:@" " atIndex:3];
        }
        if (number.length > 8 && ![[number substringWithRange:NSMakeRange(8, 1)] isEqualToString:@" "]) {
            [mutStr insertString:@" " atIndex:8];
        }
    }
    return mutStr;
}


/**
 用于剔除数组中重复的号码
 
 @param mutArr 传人的待处理的数组
 @return 返回处理好的数组
 */
+ (NSMutableArray *)filterAboutEqualPhone:(NSMutableArray *)mutArr {
    
    NSMutableArray *array = [mutArr mutableCopy];
    for (int i = 0; i < mutArr.count; i++) {
        
        AddressBookPerson *personI = mutArr[i];
        for (int j = i+1; j < mutArr.count; j++) {
            AddressBookPerson *personJ = mutArr[j];
            
            if ([personI.phoneNumber isEqualToString:personJ.phoneNumber]) {
                
                [array removeObjectAtIndex:i];
            }
            continue;
        }
    }
    return array;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
